<?php
class friend { 
    var $f_u_id;
    var $f_list;


    function Delete(){

        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();

        $q = " delete  from friend where f_u_id ='".$this->f_u_id."' " ;
        $rs = $DB->EjecutarQuery($q);

        $DB->DesconectarBD();
        return $rs;
    }

    function Update(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        $query = " " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;  
    }

    function GetData(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
         
        $query = " Select * from friend where f_u_id ='".$this->f_u_id."' ";
        $rs = $DB->ObtenerData($query, "friend" );

        $this->f_u_id = $rs[0]["f_u_id"];
        $this->f_list = $rs[0]["f_list"];

        $DB->DesconectarBD();        
    }

    function Save(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        $query = " INSERT INTO friend (
                     f_u_id, f_list)
                    VALUES (NULL, '$this->f_list');" ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;        
    }
    
    function GetList($vals = false, $orderby = false, $lim= false){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        if ($_REQUEST["seccion"] == "friend" ) { //modulo friend
        
            if(!isset($_REQUEST["li"])){
                $li = 0;
            }else{
                $li = $_REQUEST["li"];
            }               

            if(isset($_REQUEST["page"])){
                $li = ($_REQUEST["page"]* $_SESSION['PREF']['LIST_LIMIT'])- $_SESSION['PREF']['LIST_LIMIT'];
            }

            if(!$vals){
                $vals = " * ";            
            }

            if(!$lim){
                $limit ="LIMIT ".$li.", ".$_SESSION['PREF']['LIST_LIMIT']." ";
            }

            if($orderby){            
                $order =" ORDER BY $orderby ";
            }else{
                $order =" ORDER BY f_list desc,  asc ";
            }

            if(isset($_REQUEST["estado"]) && $_REQUEST["estado"] <> 99 ){ 
                $where .= " and  = ".$_REQUEST["estado"]."  ";
            }   

            if($_REQUEST["filtro"]){
                $query = " Select $vals from friend where  like '%".$_REQUEST["filtro"]."%' $where
                                $order  $limit ";
            }else{
                $query = " Select $vals from friend where 1=1 $where   $order  $limit   ";
            }
            
        } else {  //desde fuera del MODULO FRIEND
            
             $query = " Select $vals from friend where  = 1 $where  ";
            
        }
        
        $rs = $DB->ObtenerData($query, "friend");

        if (trim($vals) != "count(*)"){

            foreach ($rs as $key => $val) {
                $f = new friend();
                $f->set_f_u_id($val["f_u_id"]);
                $f->set_f_list($val["f_list"]);
                $rs2[] = $f;
            }

            $rs = $rs2;

            include_once 'recursos/funciones.php';
            $e = getEstado();        
            if(is_array($rs)){
                foreach ($rs as $key => $value) {
                    if ($value[""] == 1) {
                        $rs[$key][""] = "<img src='images/png/estado_habilitado.png' />".$e[$value[""]];
                    } else {
                        $rs[$key][""] = "<img src='images/png/estado_deshabilitado.png' />".$e[$value[""]];
                    }  
                }
            }
        }
        $DB->DesconectarBD();      
        return $rs;                
    }

    function get_f_u_id(){
        return $this->f_u_id;
    }
    function set_f_u_id($val){
        $this->f_u_id = $val;
    }

    function get_f_list(){
        return $this->f_list;
    }
    function set_f_list($val){
        $this->f_list = $val;
    }

}